package routines;

import java.lang.Integer;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.*;
import routines.Lot;
import routines.Print;

/**
 * Entity implementation class for Entity: Application
 *
 */
@Entity
@Table(name="application")
public class Application extends Print {

	

	private long id;
	private Long offer_source_id;
	private Long raiting_source_id;
	private String journalNumber;
	private Lot lot;
	private Integer appRating;
	private Map<String,LegalEntity> appParticipants;
	private BigDecimal offer;
	private Date appDate;
	private Date publishdate;
	private Date signDate;
	private Date protocolDate;
	private String appRejectedReason;
	private Boolean rejected = false;
	private String place;
	private String href;
	private Date inserted = new Date();


	@Id
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "sqe_application_gen")
	@SequenceGenerator(name = "sqe_application_gen", sequenceName = "seq_applications")
	@Column(name = "application_id")
	public long getId() {
		return id;
	}


	public void setId(long iD) {
		id = iD;
	}

	@Column(columnDefinition = "TEXT")
	public void setHref(String href) {
		this.href = href;
	}


	@Column(columnDefinition = "TEXT")
	public String getHref() {
		return href;
	}


	public void setPlace(String place) {
		this.place = place;
	}


	public String getPlace() {
		return place;
	}


	public void setAppRejectedReason(String appRejectedReason) {
		this.appRejectedReason = appRejectedReason;
		if (appRejectedReason!=null)
			rejected = true;
	}


	@Column(columnDefinition = "TEXT")
	public String getAppRejectedReason() {
		return appRejectedReason;
	}


	public void setRejected(Boolean rejected) {
		this.rejected = rejected;
	}


	@Column(nullable = true)
	public Boolean isRejected() {
		return rejected;
	}


	public Date getPublishdate() {
		return publishdate;
	}


	public void setPublishdate(Date publishdate) {
		this.publishdate = publishdate;
	}


	public Date getAppDate() {
		return appDate;
	}


	public void setAppDate(Date appDate) {
		this.appDate = appDate;
	}


	public BigDecimal getOffer() {
		return offer;
	}


	public void setOffer(BigDecimal offer) {
		this.offer = offer;
	}

	public void setOffer(Double offer) {
		this.offer = new BigDecimal(offer);
	}


	@ManyToMany
	@MapKey(name = "inn")
	public Map<String,LegalEntity> getAppParticipants() {
		return appParticipants;
	}


	public void setAppParticipants(Map<String,LegalEntity> appParticipants) {
		this.appParticipants = appParticipants;
	}


	public Integer getAppRating() {
		return appRating;
	}


	public void setAppRating(Integer appRating) {
		this.appRating = appRating;
	}


	public Application() {
	}   
	
	
	@Column(name = "journalNumber")
	public String getJournalNumber() {
		return this.journalNumber;
	}

	public void setJournalNumber(String journalNumber) {
		this.journalNumber = journalNumber;
	}   
	
	
	@JoinColumn(name = "lot_id", nullable = true)
	@ManyToOne
	public Lot getLot() {
		return this.lot;
	}

	public void setLot(Lot lot) {
		this.lot = lot;
	}

	public void AddParticipant(LegalEntity le) {
		if (appParticipants == null)
			appParticipants = new HashMap<String, LegalEntity>();
		LegalEntity l = appParticipants.get(le.getInn()); 
		if (l==null)// le.setLegalentityId(l.getLegalentityId());
		appParticipants.put(le.getInn(), le);
	}


	public void setInserted(Date inserted) {
		this.inserted = inserted;
	}


	public Date getInserted() {
		return inserted;
	}


	public void setOffer_source_id(Long offer_source_id) {
		this.offer_source_id = offer_source_id;
	}


	public Long getOffer_source_id() {
		return offer_source_id;
	}


	public void setRaiting_source_id(Long raiting_source_id) {
		this.raiting_source_id = raiting_source_id;
	}


	public Long getRaiting_source_id() {
		return raiting_source_id;
	}


	public void setSignDate(Date signDate) {
		this.signDate = signDate;
	}


	public Date getSignDate() {
		return signDate;
	}


	public void setProtocolDate(Date protocolDate) {
		this.protocolDate = protocolDate;
	}


	public Date getProtocolDate() {
		return protocolDate;
	}




   
}
